<template>
	<uni-nav-bar
		v-if="!sheep.$store('app').isWxBrowser"
		left-icon="left"
		title="好友分享"
		fixed
		@clickLeft="goBack"
		height="100rpx"
	/>
	<view class="share-container">
		<view>
			<f-shareFriends-top
				:num="sheep.$store('cart').goodsCount"
				:shareNum="shareNum"
				:isDot="isDot"
			/>
		</view>
		<view class="show-list">
			<f-shareFriends-list :dataList="showDataList" />
		</view>
		<!-- 未登录弹窗提示 -->
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog
				type="center"
				cancelText="取消"
				confirmText="去登录"
				title="提示"
				content="您暂未登录,请选择是否去登录"
				@confirm="dialogConfirm"
				@close="dialogClose"
			/>
		</uni-popup>
	</view>
</template>

<script setup>
	import { ref, toRaw, computed } from 'vue';
	import { onLoad } from '@dcloudio/uni-app';
	import sheep from '@/sheep';
	import shareApi from './../../sheep/api/share.js';

	const emit = defineEmits();
	const props = defineProps({
		dataList: {
			type: Array,
			default: () => {
				return [];
			},
		},
	});

	const isLogin = computed(() => sheep.$store('user').isLogin);

	const alertDialog = ref(null);
	const shareCode = ref('');
	const showDataList = ref([]);
	const isDot = ref(false);
	const num = ref(0);
	const shareNum = ref(0);
	onLoad(() => {
		let { params } = sheep.$helper.getCurrentPagePath();
		shareCode.value = params.no;
		let data = {
			no: shareCode.value,
		};
		if (isLogin.value) {
			shareApi.getLoginShareInfo(data).then((res) => {
				showDataList.value = res.data.images;
				shareNum.value = res.data.count;
			});
			isDot.value = false;
			sheep.$store('cart').getList();
		} else {
			shareApi.getNotloginShareInfo(data).then((res) => {
				showDataList.value = res.data.images;
				shareNum.value = res.data.count;
				alertDialog.value.open();
			});
			isDot.value = true;
		}
	});
	const dialogConfirm = () => {
		sheep.$router.go('/pages/index/login');
	};
	const dialogClose = () => {
		alertDialog.value.close();
	};

	const goBack = () => {
		sheep.$router.back();
	};
</script>

<style scoped lang="scss">
	.share-container {
		padding: 24rpx 32rpx 0;

		.show-list {
			margin-top: 32rpx;
			padding-bottom: 24rpx;
		}
	}
</style>
